package com.szqhyxj.youxiangju.biz.set.forgetpassword;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.szqhyxj.youxiangju.BaseActivity;
import com.szqhyxj.youxiangju.R;
import com.szqhyxj.youxiangju.biz.web.WebActivity;
import com.szqhyxj.youxiangju.sys.components.NavigationBar;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by leung on 2018/11/5.
 */

public class ForgetPasswordActivity extends BaseActivity implements NavigationBar.NavigationBarListener, ForgetPassWordContract.View {

    @BindView(R.id.navigationBar)
    NavigationBar navigationBar;
    @BindView(R.id.tv_phone)
    TextView tvPhone;
    @BindView(R.id.registerPhone)
    EditText registerPhone;
    @BindView(R.id.tv_code)
    TextView tvCode;
    @BindView(R.id.registerCode)
    EditText registerCode;
    @BindView(R.id.acquire)
    TextView acquire;
    @BindView(R.id.tv_pwd)
    TextView tvPwd;
    @BindView(R.id.pwd)
    EditText password;
    @BindView(R.id.verify_pwd)
    TextView verify_pwd;
    @BindView(R.id.registerVerifyPassword)
    EditText VerifyPassword;
    @BindView(R.id.registered)
    TextView registered;


    ForgetPassWordPresenter presenter;

    public static void start(Activity activity) {
        Intent intent = new Intent();
        intent.setClass(activity, ForgetPasswordActivity.class);
        activity.startActivity(intent);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_forget_password);
        ButterKnife.bind(this);
        navigationBar.setNavigationBarListener(this);
        presenter = new ForgetPassWordPresenter(this);
        registerPhone.addTextChangedListener(new SimpleTextWatcher() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                presenter.setPhone(s.toString());
            }
        });
        registerCode.addTextChangedListener(new SimpleTextWatcher() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                presenter.setCode(s.toString());
            }
        });
        password.addTextChangedListener(new SimpleTextWatcher() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                presenter.setPassword(s + "");
            }
        });
        password.addTextChangedListener(new SimpleTextWatcher() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                presenter.setPassword(s.toString());
            }
        });

        VerifyPassword.addTextChangedListener(new SimpleTextWatcher() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                presenter.setVerifyPassword(s.toString());
            }
        });



    }

    public abstract static class SimpleTextWatcher implements TextWatcher {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    }

    @Override
    public void navigationLeft() {
        finish();
    }

    @Override
    public void navigationRight() {

    }


    @OnClick({R.id.acquire, R.id.registered})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.acquire:
                presenter.acquireVerificationCode();
                break;
            case R.id.registered:
                presenter.registered();
                break;

        }
    }

    @Override
    public void showChangeEnable() {
        registered.setBackgroundResource(R.drawable.background_btn04);
        registered.setEnabled(true);
    }

    @Override
    public void showChangeDisable() {
        registered.setBackgroundResource(R.drawable.background_btn_grey04);
        registered.setEnabled(false);
    }

    @Override
    public void showAcquiringVerificationCode(int number) {
        acquire.setText(String.format("%ss", String.valueOf(number)));
        acquire.setEnabled(false);
    }

    @Override
    public void showAcquiredVerificationCode() {
        acquire.setText("发送");
        acquire.setEnabled(true);
    }

    @Override
    public void showAcquiredVerificationCodeSuccess() {
        Toast.makeText(this, "验证码已发送", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void showAcquiredVerificationCodeFail(String s) {
        Toast.makeText(this, s, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void showSuccess() {
        this.finish();
    }

    @Override
    public void showFali(String s) {
        Toast.makeText(this, s, Toast.LENGTH_SHORT).show();
    }
}
